import { _decorator, Component, instantiate, Label, Node, Prefab, resources, Sprite, SpriteFrame } from 'cc';
import { Constant } from '../Constant';
import { EventManager, IncidentEvent } from '../EventManager';
import { BundleManager } from '../BundleManager';
const { ccclass, property } = _decorator;

@ccclass('taskPanel')
export class taskPanel extends Component {
    @property(SpriteFrame)
    OverSprit: SpriteFrame = null;
    private Content: Node = null;
    Show() {
        this.Content = this.node.getChildByPath("任务界面/Content");
        this.InitTaskPanel();
        EventManager.on(IncidentEvent.OverTask, this.OverTask, this);
    }

    //完成任务
    OverTask(index: number) {
        this.Content.children[index].getChildByName("完成状态").getComponent(Sprite).spriteFrame = this.OverSprit;
    }

    //初始化任务界面
    InitTaskPanel() {
        resources.load("Prefab/任务", Prefab, (err, data) => {
            for (let i = 0; i < Constant.TaskText.length; i++) {
                let pre = instantiate(data);
                pre.setParent(this.Content);
                pre.getChildByName("描述").getComponent(Label).string = Constant.TaskText[i];
            }
        })

    }

    //关闭任务界面
    Exit() {
        this.node.active = false;
    }
}


